package com.itshidu.game.controller;

import com.itshidu.game.entity.Hero;
import com.itshidu.game.entity.User;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class BaseController {

    public User getCurrentUser() {
        return (User) getRequest().getSession().getAttribute("current-user");
    }
    public void setCurrentUser(User user) {
        getRequest().getSession().setAttribute("current-user",user);
    }

    public Hero getCurrentHero() {
        return (Hero) getRequest().getSession().getAttribute("current-hero");
    }
    public void setCurrentHero(Hero hero) {
        getRequest().getSession().setAttribute("current-hero",hero);
    }

    public ServletRequestAttributes getRequestAttributes() {
        return (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    }

    public HttpServletRequest getRequest() {
        return getRequestAttributes().getRequest();
    }


}
